<?php
namespace Home\Controller;
use Think\Controller;
class UserCenterController extends Controller {
    //TP构造函数
    public function _initialize(){
        //自动加载的类
        new \Org\Autoload();
        if(session('member_id')==''){
            echo "<script>alert('您没有登录，请您登录后再访问此页面');window.location.href='/user/login';</script>";exit;
        }
        $this->member_id=$this->member_info['member_id'];
        //echo $member_id;exit;
    }
    //会员中心 首页
    public function index(){
        $Model=D("Member");
        //print_r($this->member_info);exit;
        $Model->member_id=$this->member_info['member_id'];
        $member_info=$Model->get_member_info();
        $user_info=$Model->get_member_info();
        //print_r($member_info);exit;
        $data['title']='首页_会员中心_找金银网';
        $data['active']='index';
        $this->assign("data", $data);
        $this->assign("user_info", $user_info);
        $this->assign("member_info", $member_info);
        $this->assign("member_id", $member_info['member_id']);
        $this->display();
    }
    //采购管理
    public function purchase_add(){
        //此处判断用户是否信息完整
        if(!$this->check_member_complete()){
            echo "<script>alert('请您填写完整后再尝试重新提交');window.location.href='/user_center/member_index';</script>";exit;
        }
        $data['title']='发布采购 会员中心 找金银网';
        $data['active']='purchase';
        $Product=D("Product");  //产品
        //$Member=D("Member");  //会员
        $Area=D("Area");  //品牌
        $Brand=D("Brand");  //品牌
        $Spec=D("Spec");  //规格
        $Unit=D("Unit");  //计量单位
        $Depot=D("Depot");  //仓库
        $DeliverTime=D("DeliverTime");  //发货时间
        $DeliverType=D("DeliverType");  //发货类型
        $ShippingType=D("ShippingType");  //物流方式
        $cat_list=$Product->get_cat_list();
        //$member_list=$Member->get_member_list();
        $brand_list=$Brand->get_brand_list();
        $Area->type=2;  //地区列表 城市一级
        $area_list=$Area->get_area_list();
        $spec_list=$Spec->get_spec_list();
        $unit_list=$Unit->get_unit_list();
        $depot_list=$Depot->get_depot_list();
        $deliver_time_list=$DeliverTime->get_deliver_time_list();
        $deliver_type_list=$DeliverType->get_deliver_type_list();
        $shipping_type_list=$ShippingType->get_shipping_type_list();
        //print_r($area_list);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("cat_list", $cat_list);
        //$this->assign("member_list", $member_list);
        $this->assign("brand_list", $brand_list);
        $this->assign("area_list", $area_list);
        $this->assign("spec_list", $spec_list);
        $this->assign("unit_list", $unit_list);
        $this->assign("depot_list", $depot_list);
        $this->assign("deliver_time_list", $deliver_time_list);
        $this->assign("deliver_type_list", $deliver_type_list);
        $this->assign("shipping_type_list", $shipping_type_list);
        $this->display();
    }
    //
    public function purchase_add_post(){
        if(!$_POST['purchase_title']||!$_POST['purchase_desc']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        if(!empty($_FILES['purchase_image']['tmp_name'])){
            //echo 29929;exit;
            //上传图片
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './data/upload/purchase/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName=md5(time());
            $info   =   $upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $purchase_image='/data/upload/purchase/'.$info['purchase_image']['savename'];
            $post['purchase_image']=$purchase_image;
        }
        $post['member_id']=$this->member_id;
        $post['purchase_time']=time();
        $post['purchase_sn']=date('YmdHis',time()).rand(001,999);
        //print_r($post);exit;
        $Model=D("Purchase");
        $Model->post=$post;
        if(!$Model->purchase_add_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/purchase_list';</script>";
    }
    private function check_member_complete(){
        $member_id=$this->member_info['member_id'];
        $Model=M();
        $sql="select count(a.member_id) as total from zjy_member as a, zjy_company as b where a.member_state=1 and a.member_id=$member_id and a.member_id=b.member_id and a.member_truename!='' and a.member_email!='' and a.member_mobile!='' and b.company_name!='' and b.company_address!='' ";
        //echo $sql;exit;
        $query=$Model->query($sql);
        $count=$query[0]['total'];
        //$count=M('Company')->where("member_id=".$member_id." and company_name!='' and company_name!=''")->count();
        if($count==0){
            return false;
        }else{
            return true;
        }
        //echo $member_id;exit;
    }
    //批量采购
    public function purchase_batch(){
        $data['title']='批量采购 会员中心 找金银网';
        $data['active']='purchase';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //采购清单 采购管理默认页
    public function purchase_list($page=1){
        $data['title']='采购清单 会员中心 找金银网';
        $data['active']='purchase'; //导航条状态
        $Model=D("Purchase");
        //参数 分页
        if(intval($page)==0){
            $page=1;
        }else{
            $page=intval($page);
        }
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        $perpage=10;  //每页显示数
        //搜索 分类
        /*if(I('post.pc_id')){
            $Model->pc_id=I('post.pc_id');
        }*/
        $Model->page=$page;
        $Model->perpage=$perpage;
        $Model->member_id=$this->member_id;
        $Model->page_type=2;   //页面类型 1现货2会员中心
        $purchase_list=$Model->get_purchase_list();
        //print_r($order_list);exit;
        $purchase_total=$Model->get_purchase_total();
        //echo $user_total;exit;
        $page_total=ceil($purchase_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['purchase_total']=$purchase_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("purchase_list", $purchase_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("data", $data);
        $this->display();
    }
    //采购清单编辑
    public function purchase_edit($id=''){
        //echo $this->member_info['member_id'];exit;
        $data['title']='采购编辑 会员中心 找金银网';
        $data['active']='purchase';
        if(intval($id)==0){
            $purchase_id=1;
        }else{
            $purchase_id=intval($id);
        }
        $Model=D("Purchase");
        $Product=D("Product");  //产品
        //$Member=D("Member");  //会员
        $Area=D("Area");  //品牌
        $Brand=D("Brand");  //品牌
        $Spec=D("Spec");  //规格
        $Unit=D("Unit");  //计量单位
        $Depot=D("Depot");  //仓库
        $DeliverTime=D("DeliverTime");  //发货时间
        $DeliverType=D("DeliverType");  //发货类型
        $ShippingType=D("ShippingType");  //物流方式
        $Model->purchase_id=$purchase_id;
        $purchase_info=$Model->get_purchase_info();
        $cat_list=$Product->get_cat_list();
        //$member_list=$Member->get_member_list();
        $brand_list=$Brand->get_brand_list();
        $Area->type=2;  //地区列表 城市一级
        $area_list=$Area->get_area_list();
        $spec_list=$Spec->get_spec_list();
        $unit_list=$Unit->get_unit_list();
        $depot_list=$Depot->get_depot_list();
        $deliver_time_list=$DeliverTime->get_deliver_time_list();
        $deliver_type_list=$DeliverType->get_deliver_type_list();
        $shipping_type_list=$ShippingType->get_shipping_type_list();
        //print_r($brand_list);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("purchase_info", $purchase_info);
        $this->assign("cat_list", $cat_list);
        //$this->assign("member_list", $member_list);
        $this->assign("brand_list", $brand_list);
        $this->assign("area_list", $area_list);
        $this->assign("spec_list", $spec_list);
        $this->assign("unit_list", $unit_list);
        $this->assign("depot_list", $depot_list);
        $this->assign("deliver_time_list", $deliver_time_list);
        $this->assign("deliver_type_list", $deliver_type_list);
        $this->assign("shipping_type_list", $shipping_type_list);
        $this->display();
    }
    //
    public function purchase_edit_post(){
        if(!$_POST['purchase_title']||!$_POST['purchase_desc']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        //产品图
        if(!empty($_FILES['purchase_image']['tmp_name'])){
            $this->purchase_mkdir(); //创建文件夹
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/purchase/'.$this->member_info['member_id'].'/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName='purchase_image_'.md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $purchase_image='/data/upload/purchase/'.$this->member_info['member_id'].'/'.$info['purchase_image']['savename'];
            $post['purchase_image']=$purchase_image;
        }
        //凭证
        if(!empty($_FILES['purchase_voucher']['tmp_name'])){
            $this->purchase_mkdir(); //创建文件夹
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/purchase/'.$this->member_info['member_id'].'/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName='purchase_voucher_'.md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $purchase_voucher='/data/upload/purchase/'.$this->member_info['member_id'].'/'.$info['purchase_voucher']['savename'];
            $post['purchase_voucher']=$purchase_voucher;
        }
        //print_r($post);exit;
        $Model=D("Purchase");
        $Model->post=$post;
        if(!$Model->purchase_edit_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/purchase_list';</script>";
    }
    //创建文件夹
    private  function purchase_mkdir(){
        if(!file_exists('./data')){
            mkdir ("./data");
        }
        if(!file_exists('./data/upload')){
            mkdir ("./data/upload");
        }
        if(!file_exists('./data/upload/purchase')){
            mkdir ("./data/upload/purchase");
        }
        if(!file_exists('./data/upload/purchase/'.$this->member_info['member_id'])){
            mkdir ('./data/upload/purchase/'.$this->member_info['member_id']);
        }
    }
    //创建文件夹
    private  function supply_mkdir(){
        if(!file_exists('./data')){
            mkdir ("./data");
        }
        if(!file_exists('./data/upload')){
            mkdir ("./data/upload");
        }
        if(!file_exists('./data/upload/supply')){
            mkdir ("./data/upload/supply");
        }
        if(!file_exists('./data/upload/supply/'.$this->member_info['member_id'])){
            mkdir ('./data/upload/supply/'.$this->member_info['member_id']);
        }
    }
    //AJAX删除
    public function ajax_purchase_del(){
        if(session('member_id')==''){
            $data['msg']='没有登录';
        }else{
            $ids[0]=I('post.purchase_id');
            $data=array();
            $Model=D("Purchase");
            $Model->ids=$ids;
            if(!$Model->purchase_delete()){
                $data['msg']='写入数据库失败,请您重新提交';exit;
            }
            $data['msg']='ok';
        }
        echo json_encode($data);
    }
    //采购意向
    public function purchase_intention(){
        $data['title']='采购意向 会员中心 找金银网';
        $data['active']='purchase';
        $Model=D("Intention");
        $Model->member_id=$this->member_id;
        $Model->intention_type=1;
        $intention_list=$Model->get_intention_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("intention_list",$intention_list);
        $this->assign("data", $data);
        $this->display();
    }
    
    //采购订单
    public function purchase_order(){
        $data['title']='采购订单 会员中心 找金银网';
        $data['active']='purchase';
        if(I('path.2')!=''){
            $page=I('path.2');
        }else{
            $page=1;
        }
        $perpage=10;
        $Model=D("Order");
        $Model->member_id=$this->member_id;
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        //搜索 分类
        /*if(I('post.pc_id')){
            $Model->pc_id=I('post.pc_id');
        }*/
        $Model->page=$page;
        $Model->perpage=$perpage;
        $order_list=$Model->get_purchase_order_list();
        //print_r($order_list);exit;
        $order_total=$Model->get_purchase_order_total();
        //echo $user_total;exit;
        $page_total=ceil($order_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['order_total']=$order_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("order_list", $order_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("data", $data);
        $this->display();
    }
    //采购订单编辑
    public function purchase_order_edit(){
        $data['title']='采购订单 会员中心 找金银网';
        $data['active']='purchase';
        $order_id=I('path.2');
        $Model=D("Order");
        $Model->order_id=$order_id;
        $order_info=$Model->get_order_info();
        //print_r($order_info);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("order_info", $order_info);
        $this->display();
    }
    //马上支付
    public function paynow(){
        if(!$_POST['order_amount']) {
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $order_amount=I('post.order_amount');
        $order_id=I('post.order_id');
        $member_balance=M('Member')->where('member_id='.$this->member_id)->getField('member_balance');
        if($member_balance<$order_amount){
            echo "<script>alert('您的账户余额已不够支付该账单，请您充值后再尝试，谢谢');window.location.href='/user_center/member_wallet_balance';</script>";exit;
        }
        //账户余额-订单金额
        $result=M('Member')->where('member_id='.$this->member_id)->setDec('member_balance',$order_amount);
        if($result === false) {
            echo "<script>alert('扣除账户余额失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        //更新订单状态表
        $data['order_state_id']=2;  //2为已支付
        $data['payment_time']=time();  //支付时间
        $result=M('Order')->where('order_id='.$order_id)->save($data);
        if($result === false) {
            echo "<script>alert('更新订单状态失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/purchase_order_edit/$order_id';</script>";
    }
    //采购订单编辑提交
    public function purchase_order_edit_post(){
        if($_POST['order_amount']!=''){
            $post=I('post.');
            //print_r($post);exit;
            $Model=D("Order");
            $Model->post=$post;
            if(!$Model->order_edit_post()){
                echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>alert('提交成功');window.location.href='/user_center/purchase_order';</script>";
        }else{
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
    }
    //供货管理
    public function supply_list($page=1){
        $data['title']='供货清单 会员中心 找金银网';
        $data['active']='supply';
        $Model=D("Supply");
        //参数 分页
        if(intval($page)==0){
            $page=1;
        }else{
            $page=intval($page);
        }
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        $perpage=10;  //每页显示数
        //搜索 分类
        $Model->page=$page;
        $Model->perpage=$perpage;
        $Model->member_id=$this->member_id;
        $Model->page_type=2;   //页面类型 1现货2会员中心
        $supply_list=$Model->get_supply_list();
        //print_r($order_list);exit;
        $supply_total=$Model->get_supply_total();
        //echo $user_total;exit;
        $page_total=ceil($supply_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['supply_total']=$supply_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("supply_list", $supply_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);

        $this->assign("data", $data);
        $this->display();
    }
    //供应清单编辑
    public function supply_edit($id=''){
        $data['title']='供应编辑 会员中心 找金银网';
        $data['active']='supply';
        if(intval($id)==0){
            $supply_id=1;
        }else{
            $supply_id=intval($id);
        }
        $Model=D("Supply");
        $Product=D("Product");  //产品
        //$Member=D("Member");  //会员
        $Area=D("Area");  //品牌
        $Brand=D("Brand");  //品牌
        $Spec=D("Spec");  //规格
        $Unit=D("Unit");  //计量单位
        $Depot=D("Depot");  //仓库
        $DeliverTime=D("DeliverTime");  //发货时间
        $DeliverType=D("DeliverType");  //发货类型
        $ShippingType=D("ShippingType");  //物流方式
        $Model->supply_id=$supply_id;
        $supply_info=$Model->get_supply_info();
        $cat_list=$Product->get_cat_list();
        //$member_list=$Member->get_member_list();
        $brand_list=$Brand->get_brand_list();
        $Area->type=2;  //地区列表 城市一级
        $area_list=$Area->get_area_list();
        $spec_list=$Spec->get_spec_list();
        $unit_list=$Unit->get_unit_list();
        $depot_list=$Depot->get_depot_list();
        $deliver_time_list=$DeliverTime->get_deliver_time_list();
        $deliver_type_list=$DeliverType->get_deliver_type_list();
        $shipping_type_list=$ShippingType->get_shipping_type_list();
        //print_r($brand_list);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("supply_info", $supply_info);
        $this->assign("cat_list", $cat_list);
        //$this->assign("member_list", $member_list);
        $this->assign("brand_list", $brand_list);
        $this->assign("area_list", $area_list);
        $this->assign("spec_list", $spec_list);
        $this->assign("unit_list", $unit_list);
        $this->assign("depot_list", $depot_list);
        $this->assign("deliver_time_list", $deliver_time_list);
        $this->assign("deliver_type_list", $deliver_type_list);
        $this->assign("shipping_type_list", $shipping_type_list);
        $this->display();
    }
    public function supply_add(){
        //此处判断用户是否信息完整
        if(!$this->check_member_complete()){
            echo "<script>alert('请您填写完整后再尝试重新提交');window.location.href='/user_center/member_index';</script>";exit;
        }
        $data['title']='发布供货 会员中心 找金银网';
        $data['active']='supply';
        $Product=D("Product");  //产品
        //$Member=D("Member");  //会员
        $Area=D("Area");  //品牌
        $Brand=D("Brand");  //品牌
        $Spec=D("Spec");  //规格
        $Unit=D("Unit");  //计量单位
        $Depot=D("Depot");  //仓库
        $DeliverTime=D("DeliverTime");  //发货时间
        $DeliverType=D("DeliverType");  //发货类型
        $ShippingType=D("ShippingType");  //物流方式
        $cat_list=$Product->get_cat_list();
        //$member_list=$Member->get_member_list();
        $brand_list=$Brand->get_brand_list();
        $Area->type=2;  //地区列表 城市一级
        $area_list=$Area->get_area_list();
        $spec_list=$Spec->get_spec_list();
        $unit_list=$Unit->get_unit_list();
        $depot_list=$Depot->get_depot_list();
        $deliver_time_list=$DeliverTime->get_deliver_time_list();
        $deliver_type_list=$DeliverType->get_deliver_type_list();
        $shipping_type_list=$ShippingType->get_shipping_type_list();
        //print_r($area_list);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("cat_list", $cat_list);
        //$this->assign("member_list", $member_list);
        $this->assign("brand_list", $brand_list);
        $this->assign("area_list", $area_list);
        $this->assign("spec_list", $spec_list);
        $this->assign("unit_list", $unit_list);
        $this->assign("depot_list", $depot_list);
        $this->assign("deliver_time_list", $deliver_time_list);
        $this->assign("deliver_type_list", $deliver_type_list);
        $this->assign("shipping_type_list", $shipping_type_list);
        $this->display();
    }
    //
    public function supply_add_post(){
        if(!$_POST['supply_title']||!$_POST['supply_desc']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        if(!empty($_FILES['supply_image']['tmp_name'])){
            //echo 29929;exit;
            //上传图片
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './data/upload/supply/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName=md5(time());
            $info   =   $upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $supply_image='/data/upload/supply/'.$info['supply_image']['savename'];
            $post['supply_image']=$supply_image;
        }
        $post['member_id']=$this->member_id;
        $post['supply_time']=time();
        $post['supply_sn']=date('YmdHis',time()).rand(001,999);
        // print_r($post);exit;
        $Model=D("Supply");
        $Model->post=$post;
        if(!$Model->supply_add_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/supply_list';</script>";
    }
    //
    public function supply_edit_post(){
        if(!$_POST['supply_title']||!$_POST['supply_desc']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        //产品图
        if(!empty($_FILES['supply_image']['tmp_name'])){
            $this->supply_mkdir(); //创建文件夹
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/supply/'.$this->member_info['member_id'].'/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName='supply_image_'.md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $supply_image='/data/upload/supply/'.$this->member_info['member_id'].'/'.$info['supply_image']['savename'];
            $post['supply_image']=$supply_image;
        }
        //凭证
        if(!empty($_FILES['supply_voucher']['tmp_name'])){
            $this->supply_mkdir(); //创建文件夹
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/supply/'.$this->member_info['member_id'].'/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName='supply_voucher_'.md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $supply_voucher='/data/upload/supply/'.$this->member_info['member_id'].'/'.$info['supply_voucher']['savename'];
            $post['supply_voucher']=$supply_voucher;
        }
        //print_r($post);exit;
        $Model=D("Supply");
        $Model->post=$post;
        if(!$Model->supply_edit_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/supply_list';</script>";
    }
    //AJAX删除
    public function ajax_supply_del(){
        if(session('member_id')==''){
            $data['msg']='没有登录';
        }else{
            $ids[0]=I('post.supply_id');
            $data=array();
            $Model=D("Supply");
            $Model->ids=$ids;
            if(!$Model->supply_delete()){
                $data['msg']='写入数据库失败,请您重新提交';exit;
            }
            $data['msg']='ok';
        }
        echo json_encode($data);
    }
    public function supply_batch(){
        $data['title']='批量供货 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function supply_batch_edit(){
        $data['title']='批量报价编辑 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function supply_batch_list(){
        $data['title']='批量报价清单 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //供应意向
    public function supply_intention(){
        $data['title']='供应意向 会员中心 找金银网';
        $data['active']='supply';
        $Model=D("Intention");
        $Model->member_id=$this->member_id;
        $Model->intention_type=2;
        $intention_list=$Model->get_intention_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("intention_list",$intention_list);
        $this->assign("data", $data);
        $this->display();
    }
    //供应订单
    public function supply_order(){
        $data['title']='供应订单 会员中心 找金银网';
        $data['active']='supply';
        if(I('path.2')!=''){
            $page=I('path.2');
        }else{
            $page=1;
        }
        $perpage=10;
        $Model=D("Order");
        $Model->member_id=$this->member_id;
        //搜索 关键词
        if(I('post.keyword')){
            $Model->keyword=I('post.keyword');
        }
        //搜索 分类
        /*if(I('post.pc_id')){
            $Model->pc_id=I('post.pc_id');
        }*/
        $Model->page=$page;
        $Model->perpage=$perpage;
        $order_list=$Model->get_supply_order_list();
        //print_r($order_list);exit;
        $order_total=$Model->get_supply_order_total();
        //echo $user_total;exit;
        $page_total=ceil($order_total/$perpage);
        //echo $page_total;exit;
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['perpage']=$perpage;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['order_total']=$order_total;
        $pager['page_total']=$page_total;
        //$cat_list=$Model->get_cat_list();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("order_list", $order_list);
        //$this->assign("cat_list", $cat_list);
        $this->assign("pager",$pager);
        $this->assign("data", $data);
        $this->display();
    }
    //供应订单编辑
    public function supply_order_edit(){
        $data['title']='供货订单 会员中心 找金银网';
        $data['active']='supply';
        $order_id=I('path.2');
        $Model=D("Order");
        $Model->order_id=$order_id;
        $order_info=$Model->get_order_info();
        //print_r($order_info);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("order_info", $order_info);
        $this->display();
    }
    //我的供应
    public function supply_for(){
        $data['title']='我的供应 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function supply_for_edit(){
        $data['title']='供应编辑 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的品牌
    public function supply_brand(){
        $data['title']='我的品牌 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function supply_brand_add(){
        $data['title']='品牌申请 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的仓库
    public function supply_warehouse(){
        $data['title']='我的仓库 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function supply_warehouse_add(){
        $data['title']='新增仓库 会员中心 找金银网';
        $data['active']='supply';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //交易管理
    public function transaction_index(){
        $data['title']='我的订单 会员中心 找金银网';
        $data['active']='transaction';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //客户管理
    public function customer_index(){
        $data['title']='申请退款及退货 会员中心 找金银网';
        $data['active']='customer';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //用户管理
    public function member_index(){
        $data['title']='账户设置 会员中心 找金银网';
        $data['active']='member';
        $Model=D("Member");
        $Model->member_id=$this->member_id;
        $user_info=$Model->get_member_info();
        $Model2=D("Company");
        $Model2->member_id=$this->member_id;
        $company_info=$Model2->get_company_info();
        $this->assign("user_info",$user_info);
        $this->assign("company_info",$company_info);
        $this->assign("data", $data);
        $this->display();
    }
    //用户设置
    public function member_index_post(){
        $post=I("post.");
        $post['default']=1;
        $Model=D("Member");
        $MemberAddress=D("MemberAddress");
        $MemberAddress->post=$post;
        $Model->post=$post;
        //dump($post);exit;
        if(!$post['member_truename']||!$post['member_sex']||!$post['member_mobile']||!$post['member_address']) {
            echo "<script>alert('提交失败，请您填写完整再重新提交');history.back(-1);</script>";exit;
        }
	//写入member表
        if(!$Model->user_edit_post()){
            echo "<script>alert('更新用户信息失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
	//增加默认地址
	if(!$MemberAddress->member_address_post()){
            echo "<script>alert('增加默认地址失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/member_index';</script>";
    }
     public function member_index_post2(){
        $post=I("post.");
        $Model=D("Company");
        $Model->post=$post;
        //dump($post);exit;
        if(!$post['company_name']||!$post['company_part']||!$post['company_position']||!$post['company_industry']||!$post['company_scale']||!$post['company_range']||!$post['company_mode']||!$post['company_tel']||!$post['company_address']||!($post['product_purchase']||!$post['product_supply'])) {
            echo "<script>alert('提交失败，请您填写完整再重新提交');history.back(-1);</script>";exit;
        }
        if(!$Model->company_edit_post()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/member_index';</script>";
    }
    //用户头像
    public function member_pic(){
        $data['title']='头像设置 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("data", $data);
        $this->assign("user_info",$user_info);
        $this->display();
    }
    public function member_pic_post(){
        $post=I("post.");
        if(!empty($_FILES['member_avatar']['tmp_name'])){
            //上传图片
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './data/upload/user/avatar/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName=md5(time());
            $info   =   $upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $member_avatar='/data/upload/user/avatar/'.$info['member_avatar']['savename'];
            $post['member_avatar']=$member_avatar;
            $Model=D("Member");
            $Model->post=$post;
            if(!$Model->user_edit_post()){
                echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
            }
            echo "<script>alert('提交成功');window.location.href='/user_center/member_pic';</script>";
        }
    }
    //收货地址
    public function member_address(){
        $data['title']='收货地址 会员中心 找金银网';
        $data['active']='member';
        $Model=D("MemberAddress");
        $Model->member_id=$this->member_id;
        $address_list=$Model->get_member_address_list();
        $address_total=$Model->get_member_address_total();
        $address_surplus=5-$address_total;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("address_list",$address_list);
        $this->assign("address_total",$address_total);
        $this->assign("address_surplus",$address_surplus);
        $this->assign("data", $data);
        $this->display();
    }
    //添加收货地址
    public function member_address_add(){
        $data['title']='添加收货地址 会员中心 找金银网';
        $data['active']='member';
        $Model=D("MemberAddress");
        $Model->member_id=$this->member_id;
        $address_total=$Model->get_member_address_total();
        $Model->address_total=$address_total;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //添加收货地址提交
    public function member_address_add_post(){
        $post=I("post.");
        $Model=D("MemberAddress");
        $Model->member_id=$this->member_id;
        $address_total=$Model->get_member_address_total();
        $Model->address_total=$address_total;
        $Model->post=$post;
        if(!$Model->member_address_add_post()){
            echo "<script>alert('提交失败，请您检查是否超出地址限制，并尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/member_address';</script>";
    }
    //编辑收货地址
    public function member_address_edit($id='1'){
        $data['title']='编辑收货地址 会员中心 找金银网';
        $data['active']='member';
        $rec_id=intval($id);
        $Model=D("MemberAddress");
        $Model->rec_id=$rec_id;
        $Model->member_id=$this->member_id;
        $address_info=$Model->get_member_address_info();
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("address_info",$address_info);
        $this->assign("data", $data);
        $this->display();
    }
    //编辑收货地址提交
    public function member_address_edit_post($id=''){
        $post=I("post.");
        $Model=D("MemberAddress");
        $rec_id=intval($id);
        // dump($rec_id);exit;
        $Model->rec_id=$rec_id;
        $Model->member_id=$this->member_id;
        // $address_total=$Model->get_member_address_total();
        // $Model->address_total=$address_total;
        $Model->post=$post;
        if(!$Model->member_address_edit_post($rec_id)){
            echo "<script>alert('提交失败，请您检查是否超出地址限制，并尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/member_address';</script>";
    }
    //AJAX删除
    public function ajax_member_address_del(){
        if(session('member_id')==''){
            $data['msg']='没有登录';
        }else{
            $ids[0]=I('post.rec_id');
            $data=array();
            $Model=D("MemberAddress");
            $Model->ids=$ids;
            if(!$Model->member_address_delete()){
                $data['msg']='写入数据库失败,请您重新提交';exit;
            }
            $data['msg']='ok';
        }
        echo json_encode($data);
    }
    //默认地址设置
    public function ajax_member_address_default_set(){
        if(session('member_id')==''){
            $data['msg']='没有登录';
        }else{
            $ids[0]=I('post.rec_id');
            $data=array();
            $Model=D("MemberAddress");
            $Model->ids=$ids;
            if(!$Model->member_address_default_set()){
                $data['msg']='写入数据库失败，请您重新提交';exit;
            }
            $data['msg']='ok';
        }
        echo json_encode($data);
    }
    //安全设置
    public function member_safe(){

        $data['title']='安全设置 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //提现绑定
    public function member_safe_cash(){
        $data['title']='提现绑定 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //手机绑定
    public function member_safe_cellphone(){
        $Model=D('Member');
        $member_mobile=$Model->where('member_id='.$this->member_id)->getField('member_mobile');
        //echo $member_email;exit;
        $data['title']='手机绑定 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("member_mobile", $member_mobile);
        $this->display();
    }
    public function member_safe_cellphone_post(){
        if(!$_POST['member_mobile']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        $post['member_id']=$this->member_id;
        //var_dump($post);exit;
        $Model=D("Member");
        $Model->post=$post;
        //查询原密码是否正确
        if($_POST['member_mobile']!=$_POST['old_member_mobile']){
            if($Model->check_mobile_exist()){
                echo "<script>alert('此手机号码已被别的用户绑定，请您选择别的手机号码绑定，谢谢');history.back(-1);</script>";exit;
            }
        }
        if(!$Model->save_member()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');history.back(-1);</script>";
    }
    //邮件绑定
    public function member_safe_email(){
        $Model=D('Member');
        $member_email=$Model->where('member_id='.$this->member_id)->getField('member_email');
        //echo $member_email;exit;
        $data['title']='邮件绑定 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("member_email", $member_email);
        $this->display();
    }
    public function member_safe_email_post(){
        if(!$_POST['member_email']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        $post['member_id']=$this->member_id;
        //var_dump($post);exit;
        $Model=D("Member");
        $Model->post=$post;
        //查询原密码是否正确
        if($_POST['member_email']!=$_POST['old_member_email']){
            if($Model->check_email_exist()){
                echo "<script>alert('此邮箱已被别的用户绑定，请您选择别的邮箱绑定，谢谢');history.back(-1);</script>";exit;
            }
        }
        if(!$Model->save_member()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');history.back(-1);</script>";
    }
    //登录密码
    public function member_safe_login_pwd(){
        $data['title']='登录密码 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    public function member_safe_login_pwd_post(){
        if(!$_POST['member_passwd']||!$_POST['new_member_passwd']||!$_POST['re_new_member_passwd']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        if($_POST['re_new_member_passwd']!=$_POST['new_member_passwd']){
            echo "<script>alert('新密码输入不一致');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        $post['member_id']=$this->member_id;
        $post['member_passwd']=md5($post['member_passwd']);
        //var_dump($post);exit;
        $Model=D("Member");
        $Model->post=$post;
        //查询原密码是否正确
        if(!$Model->check_password()){
            echo "<script>alert('原密码错误，请您重新提交');history.back(-1);</script>";exit;
        }
        $post['member_passwd']=md5($post['re_new_member_passwd']);
        $Model->post=$post;
//        dump($post);exit;
        if(!$Model->save_member()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');window.location.href='/user_center/member_safe';</script>";
    }
    //支付密码
    public function member_safe_pay_pwd(){
        $data['title']='支付密码 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //实名认证
    public function member_safe_realname(){
        $Model=D('Member');
        $member_info=$Model->field('member_name,member_truename,member_idcard_num,member_idcard_image')->where('member_id='.$this->member_id)->find();
        $data['title']='实名认证 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("member_info", $member_info);
        $this->display();
    }
    public function member_safe_realname_post(){
        if(!$_POST['member_truename']||!$_POST['member_idcard_num']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        $post['member_id']=$this->member_id;
        //var_dump($post);exit;
        $Model=D("Member");
        //查询是否存在
        if($_POST['member_idcard_num']!=$_POST['old_member_idcard_num']){
            if($Model->check_idcard_num_exist()){
                echo "<script>alert('此身份证号码已被别的用户绑定，请您选择别的身份证号码绑定，谢谢');history.back(-1);</script>";exit;
            }
        }
        if(!empty($_FILES['member_idcard_image']['tmp_name'])){
            //上传图片
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/member/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName=md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $member_idcard_image='/data/upload/member/'.$info['member_idcard_image']['savename'];
            $post['member_idcard_image']=$member_idcard_image;
        }
        //print_r($post);exit;
        $Model->post=$post;
        if(!$Model->save_member()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');history.back(-1);</script>";
    }
    //证件上传
    public function member_safe_license(){
        $data['title']='证件上传 会员中心 找金银网';
        $data['active']='member';
        $Member=D('Member');
        $member_id=$this->member_id;
        $License=D('License');
        $license_list=$License->get_license_list($member_id);
//        dump($license_list);exit;
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("license_list",$license_list);
        $this->assign("data", $data);
        $this->display();
    }
    public function member_safe_license_post(){
        if(!$_POST['license_name']||!$_FILES['license_image_url']){
            echo "<script>alert('请您填写完整后再尝试重新提交');history.back(-1);</script>";exit;
        }
        $post=I('post.');
        $member_id=$this->member_id;
        $Company=M('Company');
        $post['company_id']=$Company->where('member_id='.$member_id)->getField('company_id');
        //var_dump($post);exit;
        $Model=D("License");
        //查询是否存在
        if($_POST['license_name']){
            if($Model->check_license_name_exist($post['company_id'],$_POST['license_name'])){
                echo "<script>alert('此证件已经上传');history.back(-1);</script>";exit;
            }
        }
        if(!empty($_FILES['license_image_url']['tmp_name'])){
            //上传图片
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize=2000000;// 设置附件上传大小 2M
            $upload->exts=array('jpg', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath='./data/upload/member/'; // 设置附件上传根目录
            $upload->savePath=''; // 设置附件上传（子）目录
            $upload->subName='';
            $upload->saveName=md5(time());
            $info=$upload->upload();
            if(!$info) {// 上传失败
                echo "<script>alert('上传失败，请您重新上传');history.back(-1);</script>";exit;
            }
            $license_image_url='/data/upload/member/'.$info['license_image_url']['savename'];
            $post['license_image_url']=$license_image_url;
        }
        //print_r($post);exit;
        $Model->post=$post;
        if(!$Model->add_license()){
            echo "<script>alert('提交失败，请您尝试重新提交');history.back(-1);</script>";exit;
        }
        echo "<script>alert('提交成功');history.back(-1);</script>";
    }
    //证件删除
    public function ajax_license_del(){
        if(session('member_id')==''){
            $data['msg']='没有登录';
        }else{
            $ids=I('post.license_id');
            $data=array();
            $Model=D("License");
            $Model->ids=$ids;
            if(!$Model->delete_license()){
                $data['msg']='写入数据库失败,请您重新提交';exit;
            }
            $data['msg']='ok';
        }
        echo json_encode($data);
    }
    //我的钱包
    public function member_wallet_balance(){
        $amount=M('Member')->where('member_id='.$this->member_id)->getField('member_balance');
        //echo $amount;exit;
        $data['title']='余额 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->assign("amount", $amount);
        $this->display();
    }
    //支付宝充值 支付到支付宝，返回信息，写入member表中
    public function alipay(){
        //echo I('post.amount');exit;
        //以下为配置信息
        //合作身份者id，以2088开头的16位纯数字
        $alipay_config['partner']		= '2088121750845274';
        //收款支付宝账号，一般情况下收款账号就是签约账号
        $alipay_config['seller_email']	= 'api@zhaojinyin.cn';
        //安全检验码，以数字和字母组成的32位字符
        $alipay_config['key']			= 'ryr5gmy3z5j8wxsqfe9jy183fe6xz0mc';
        //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
        //签名方式 不需修改
        $alipay_config['sign_type']    = strtoupper('MD5');
        //字符编码格式 目前支持 gbk 或 utf-8
        $alipay_config['input_charset']= strtolower('utf-8');
        //ca证书路径地址，用于curl中ssl校验
        //请保证cacert.pem文件在当前文件夹目录中
        $alipay_config['cacert']    = getcwd().'\\cacert.pem';
        //访问模式,根据自己的服务器是否支持ssl访问，若支持请选择https；若不支持请选择http
        $alipay_config['transport']    = 'http';
        //以下开始操作
        vendor('Alipay.Corefunction');
        vendor('Alipay.Md5function');
        vendor('Alipay.Notify');
        vendor('Alipay.Submit');
        //支付类型
        $payment_type = "1";
        //必填，不能修改
        //服务器异步通知页面路径
        $notify_url = SELF_URL."/user_center/notify_url";
        //需http://格式的完整路径，不能加?id=123这类自定义参数
        //页面跳转同步通知页面路径
        $return_url = SELF_URL."/user_center/return_url";
        //需http://格式的完整路径，不能加?id=123这类自定义参数，不能写成http://localhost/
        //*****************************提交的商户信息**************************************
        //商户订单号
        $amount=I('post.amount');
        $out_trade_no =date('YmdHis').rand(001,999);
        session($out_trade_no,$amount);
        //商户网站订单系统中唯一订单号，必填
        //订单名称
        $subject = '充值'.$amount.'元到找金银网';
        //必填
        //付款金额
        $total_fee =$amount;
        //必填
        //订单描述
        $body = $subject;
        //商品展示地址
        $show_url =SELF_URL.'/user_center/member_wallet_balance';
        //需以http://开头的完整路径，例如：http://www.商户网址.com/myorder.html
        //防钓鱼时间戳
        $anti_phishing_key = "";
        //若要使用请调用类文件submit中的query_timestamp函数
        //客户端的IP地址
        $exter_invoke_ip = "";
        //非局域网的外网IP地址，如：221.0.0.1
        //构造要请求的参数数组，无需改动
        $parameter = array(
            "service" => "create_direct_pay_by_user",
            "partner" => trim($alipay_config['partner']),
            "seller_email" => trim($alipay_config['seller_email']),
            "payment_type"	=> $payment_type,
            "notify_url"	=> $notify_url,
            "return_url"	=> $return_url,
            "out_trade_no"	=> $out_trade_no,
            "subject"	=> $subject,
            "total_fee"	=> $total_fee,
            "body"	=> $body,
            "show_url"	=> $show_url,
            "anti_phishing_key"	=> $anti_phishing_key,
            "exter_invoke_ip"	=> $exter_invoke_ip,
            "_input_charset"	=> trim(strtolower($alipay_config['input_charset']))
        );
        //建立请求
        $alipaySubmit = new \AlipaySubmit($alipay_config);
        $html_text = $alipaySubmit->buildRequestForm($parameter,"get", "确认");
        echo $html_text;
    }
    //
    public function notify_url(){
        //以下为配置信息
        //合作身份者id，以2088开头的16位纯数字
        $alipay_config['partner']		= '2088121750845274';
        //收款支付宝账号，一般情况下收款账号就是签约账号
        $alipay_config['seller_email']	= 'api@zhaojinyin.cn';
        //安全检验码，以数字和字母组成的32位字符
        $alipay_config['key']			= 'ryr5gmy3z5j8wxsqfe9jy183fe6xz0mc';
        //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
        //签名方式 不需修改
        $alipay_config['sign_type']    = strtoupper('MD5');
        //字符编码格式 目前支持 gbk 或 utf-8
        $alipay_config['input_charset']= strtolower('utf-8');
        //ca证书路径地址，用于curl中ssl校验
        //请保证cacert.pem文件在当前文件夹目录中
        $alipay_config['cacert']    = getcwd().'\\cacert.pem';
        //访问模式,根据自己的服务器是否支持ssl访问，若支持请选择https；若不支持请选择http
        $alipay_config['transport']    = 'http';
        vendor('Alipay.Corefunction');
        vendor('Alipay.Md5function');
        vendor('Alipay.Notify');
        vendor('Alipay.Submit');
        //计算得出通知验证结果
        $alipayNotify = new \AlipayNotify($alipay_config);
        $verify_result = $alipayNotify->verifyNotify();
        if($verify_result) {//验证成功
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //请在这里加上商户的业务逻辑程序代
            //——请根据您的业务逻辑来编写程序（以下代码仅作参考）——
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
            //商户订单号
            $out_trade_no = $_POST['out_trade_no'];
            //支付宝交易号
            $trade_no = $_POST['trade_no'];
            //交易状态
            $trade_status = $_POST['trade_status'];
            if($_POST['trade_status'] == 'TRADE_FINISHED') {
                //判断该笔订单是否在商户网站中已经做过处理
                //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
                //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                //如果有做过处理，不执行商户的业务程序
                //注意：
                //退款日期超过可退款期限后（如三个月可退款），支付宝系统发送该交易状态通知
                //调试用，写文本函数记录程序运行情况是否正常
                //logResult("这里写入想要调试的代码变量值，或其他运行的结果记录");
            }
            else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
                //判断该笔订单是否在商户网站中已经做过处理
                //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
                //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                //如果有做过处理，不执行商户的业务程序
                //注意：
                //付款完成后，支付宝系统发送该交易状态通知
                //调试用，写文本函数记录程序运行情况是否正常
                //logResult("这里写入想要调试的代码变量值，或其他运行的结果记录");
            }
            //——请根据您的业务逻辑来编写程序（以上代码仅作参考）——
            echo "success";		//请不要修改或删除
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        }
        else {
            //验证失败
            echo "fail";
            //调试用，写文本函数记录程序运行情况是否正常
            //logResult("这里写入想要调试的代码变量值，或其他运行的结果记录");
        }
    }
    public function return_url(){
        //以下为配置信息
        //合作身份者id，以2088开头的16位纯数字
        $alipay_config['partner']		= '2088121750845274';
        //收款支付宝账号，一般情况下收款账号就是签约账号
        $alipay_config['seller_email']	= 'api@zhaojinyin.cn';
        //安全检验码，以数字和字母组成的32位字符
        $alipay_config['key']			= 'ryr5gmy3z5j8wxsqfe9jy183fe6xz0mc';
        //↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
        //签名方式 不需修改
        $alipay_config['sign_type']    = strtoupper('MD5');
        //字符编码格式 目前支持 gbk 或 utf-8
        $alipay_config['input_charset']= strtolower('utf-8');
        //ca证书路径地址，用于curl中ssl校验
        //请保证cacert.pem文件在当前文件夹目录中
        $alipay_config['cacert']    = getcwd().'\\cacert.pem';
        //访问模式,根据自己的服务器是否支持ssl访问，若支持请选择https；若不支持请选择http
        $alipay_config['transport']    = 'http';
        vendor('Alipay.Corefunction');
        vendor('Alipay.Md5function');
        vendor('Alipay.Notify');
        vendor('Alipay.Submit');
        //计算得出通知验证结果
        $alipayNotify = new \AlipayNotify($alipay_config);
        $verify_result = $alipayNotify->verifyReturn();
        if($verify_result) {//验证成功
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //请在这里加上商户的业务逻辑程序代码
            //——请根据您的业务逻辑来编写程序（以下代码仅作参考）——
            //获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表
            //商户订单号
            $out_trade_no = $_GET['out_trade_no'];
            //支付宝交易号
            $trade_no = $_GET['trade_no'];
            //交易状态
            $trade_status = $_GET['trade_status'];
            if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
                //判断该笔订单是否在商户网站中已经做过处理
                //如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
                //如果有做过处理，不执行商户的业务程序
            }
            else {
                echo "trade_status=".$_GET['trade_status'];
            }
            //echo "验证成功<br />";
            //***************************************支付成功后的代码**********************************************
            //echo $this->member_id;exit;
            //echo session($out_trade_no);exit;
            $amount=addslashes($_GET['total_fee']);
            //echo $amount;exit;
            $Model=D('Member');
            $condition['member_id'] = $this->member_id;
            //$data['member_balance']=$amount;  //充值的金额
            $result=$Model->where($condition)->setInc('member_balance',$amount);
            if($result === false) {
                //echo '您已经成功充值'.$amount.'元,但写入数据库错误，请您联系客服解决此问题';
                header("location: ".SELF_URL."/user_center/member_wallet_balance");exit;
            }else{
                //echo '您已经成功充值'.$amount.'元';
                header("location: ".SELF_URL."/user_center/member_wallet_balance");exit;
            }
            //——请根据您的业务逻辑来编写程序（以上代码仅作参考）——
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        }
        else {
            //验证失败
            //如要调试，请看alipay_notify.php页面的verifyReturn函数
            echo "验证失败";
        }
    }
    //我的代金券
    public function member_wallet_voucher(){
        $data['title']='代金券 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的积分
    public function member_wallet_score(){
        $data['title']='积分 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的发票
    public function member_invoice(){
        $data['title']='我的发票 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的发票抬头
    public function member_invoice_header(){
        $data['title']='我的发票抬头 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的好友
    public function member_friend(){
        $data['title']='我的好友 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的收藏
    public function member_fov(){
        $data['title']='我的收藏 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的收藏货品
    public function member_fov_goods(){
        $data['title']='我的收藏货品 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的收藏商家
    public function member_fov_shop(){
        $data['title']='我的收藏商家 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的评论
    public function member_comment(){
        $data['title']='我的评论 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的消息
    public function member_message(){
        $data['title']='我的消息 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }
    //我的消息
    public function member_message_send(){
        $data['title']='发送消息 会员中心 找金银网';
        $data['active']='member';
        $Member=D("Member");
        $Member->member_id=$this->member_id;
        $user_info=$Member->get_member_info();
        $this->assign("user_info", $user_info);
        $this->assign("data", $data);
        $this->display();
    }

    //地区四级菜单ajax
    public function area_ajax(){
        $post=I("post.");
        $Model=D("Area");
        $Model->parent=$post['parent'];
        $list=$Model->get_area_list2();
        $data=$list;
        echo json_encode($data);
    }

}